﻿using BLL;
using MODEL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Loginter.承运单管理
{
    public partial class AddUpdateCarriers : System.Web.UI.Page
    {
        CarrierBLL carrbll = new CarrierBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InsertCrr();
            }
        }

        private void InsertCrr()
        {
            int start = 0;
            //合计费用
           float come = float.Parse(txt_InsuranceCost.Text.Trim()) + float.Parse(txt_TransportCost.Text.Trim()) + float.Parse(txt_OtherCost.Text.Trim());
            //获取数据并赋值
            CarrierinfoMODEL car = new CarrierinfoMODEL()
            {
                SendCompany = txt_SendCompany.Text.Trim(),//发货单位
                SendAddress = txt_SendCompanyAddress.Text.Trim(),//发货单位地址
                SendLinkman = txt_SendLinkMan.Text.Trim(),//发货人
                SendPhone = txt_SendPhone.Text.Trim(),//发货人电话
                ReceiveCompany = txt_ReceiveCompany.Text.Trim(),//收货单位
                FK_ReceiveAddress = txt_ReceiveCompanyAddress.Text.Trim(),//收货单位地址
                ReceiveLinkman = txt_ReceiveLinkMan.Text.Trim(),//收货人/联系人
                ReceviePhone = txt_ReceivePhone.Text.Trim(),//收货人电话/联系人电话
                FinishedState = start,//完成情况
                InsuranceCosst = float.Parse(txt_InsuranceCost.Text.Trim()),//保险费
                TransportCost = float.Parse(txt_TransportCost.Text.Trim()),//运费
                OtherCost = float.Parse(txt_OtherCost.Text.Trim()),//其他费用
                TotalCost = come,//合计费用
                Remark = txt_Reamk.Text.Trim(),//备注
                UserID = 1
            };
            //调用方法
            int rest = carrbll.InsertCarriage(car);
            if (rest > 0)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('插入成功！'); location.href='CarriersGuanli.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('插入失败！');</script>");
            }
        }

        protected void btn_inserCarriers_Click(object sender, EventArgs e)
        {
            InsertCrr();
        }
    }
}